home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / FLAT.ZIP / FLAT.C < prev    next >
C/C++ Source or Header  |  1993-07-10  |  8KB  |  291 lines

  1. #define WIN31
  2. #include <windows.h>
  3. /* For the fancy looking Borland dialog box routines */
  4. #ifdef USES_BWCC
  5. #include <bwcc.h>
  6. #endif
  7. #include "flatm.h"
  8. #pragma hdrstop
  9. #include "flatadd.h"
  10. #include "flatdata.h"
  11. #include "flatfile.h"
  12. #include "flatlist.h"
  13. #include "flatsear.h"
  14. #ifdef USES_MEMCHECK
  15. /* Memory checking routines  by StratosWare Corp. */
  16. #include "\wmemchec\memcheck.h"
  17. #endif
  18.  
  19. /*--------------------------------------------
  20. -
  21. -          FLAT.C for Flat Windows Program
  22. -
  23. -     A simple flat database developed to keep
  24. -     track of our Shareware sales.  This code
  25. -     shows how to put together several basic
  26. -     Windows routines to build listboxes and
  27. -     dialog boxes that list and extract user
  28. -     information.  Included is a linked list
  29. -     sort routine, International date format
  30. -     routines, some quick & dirty memory routines,
  31. -     and some data search routines. 
  32. -
  33. -               Dennis R. Fischer
  34. -                 Denam Systems
  35. -          1115 Madison St. NE  Suite 226
  36. -              Salem, Oregon  97303
  37. -
  38. -             CompuServe 70405,1422
  39. -
  40. -        Developed with Borland 3.1 Compiler
  41. -
  42. -     Free for the taking but please give credit
  43. -                where credit is do
  44. -
  45. ----------------------------------------------*/
  46.  
  47.  
  48. /*---------------------------------------------
  49. -
  50. -              *** Special Thanks ***
  51. -
  52. -  I would like to offer my special thanks to
  53. -  two individuals that have helped make this
  54. -  project so much easier.  They are:
  55. -
  56. -     Horst G. Brueckner
  57. -     Adelsdorf, Germany
  58. -     CompuServe 100015,1534
  59. -
  60. -     Flavelle Ballen
  61. -     Toronto, Canada
  62. -     CompuServe 76516,23
  63. -
  64. -  Horst developed the 'quick & dirty' memory
  65. -  manager routines (memman.c) that is used in
  66. -  the memory procedures.  The complete file (memman.zip)
  67. -  can be found on CompuServe in the Microsoft
  68. -  Windows Forum
  69. -
  70. -  Flave developed the procedures (see the 'tTaskEntry'
  71. -  structure & WndProc()) that helps break up the 'switch
  72. -  from hell'.  The complete file (tswitc.zip) that explains
  73. -  the procedure can be found on CompuServe in the
  74. -  Borland Windows Forum.
  75. -
  76. -----------------------------------------------------*/
  77.  
  78.  
  79. /*-----------------------------------------------------
  80. -
  81. -                     #defines
  82. -
  83. -  USES_BWCC
  84. -  If you are compiling this program with a Borland
  85. -  compiler, defining USES_BWCC includes the fancy
  86. -  looking 'chiseled steel' dialog boxes
  87. -
  88. -  USES_MEMCHECK
  89. -  If you have MemCheck by StratosWare Corp., defining
  90. -  USES_MEMCHECK will add the routines to your code.
  91. -  MemCheck is a memory checking package that checks
  92. -  for memory allocation errors.  It looks for such
  93. -  things as memory overwrites, memory leakage,
  94. -  'out-of-memory' conditions, invalid pointers,
  95. -  and etc.  This is an excellent package and can be
  96. -  purchased from:
  97. -
  98. -    StratosWare Corporation
  99. -    1756 Plymouth Road
  100. -    Suite 1500
  101. -    Ann Arbor, MI  48105
  102. -
  103. -    Phone: (313) 996-2944
  104. -    Fax: (313) 747-8519
  105. -    CompuServe: 70244,1372
  106. -
  107. -----------------------------------------------------*/
  108.  
  109. /*-----------------------------------------------------
  110. -
  111. -                   Internet EMail
  112. -
  113. -  For those of you using Internet, we can be reached
  114. -  by addressing your mail to:
  115. -
  116. -    Dennis R. Fischer --- 70405.1422@compuserve.com
  117. -    Horst G. Brueckner -- 100015.1534@compuserve.com
  118. -    Flavelle Ballen  ---- 76516.23@compuserve.com
  119. -    StratosWare Corp. --- 70244.1372@compuserve.com
  120. -
  121. -----------------------------------------------------*/
  122.  
  123. #define TASKPROC  LONG CALLBACK
  124.  
  125. typedef struct
  126.         {
  127.         WORD msg;
  128.                 LONG (CALLBACK *fnc)(HWND, UINT, WPARAM, LPARAM);
  129.         } tTaskEntry;
  130.  
  131. TASKPROC WMCreate (HWND, UINT, WPARAM, LPARAM);
  132. TASKPROC WMCommand(HWND, UINT, WPARAM, LPARAM);
  133. TASKPROC WMWininichange (HWND, UINT, WPARAM, LPARAM);
  134. LONG CALLBACK _export WndProc(HWND, UINT, WPARAM, LPARAM);
  135.  
  136. static tTaskEntry TaskList[] =
  137.                 {
  138.                 {WM_CREATE,          WMCreate},
  139.                                 {WM_WININICHANGE,    WMWininichange},
  140.                                 {WM_COMMAND,         WMCommand},
  141.                 {WM_NULL,            DefWindowProc}
  142.                                 };
  143.  
  144.  
  145. #pragma argsused
  146. int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,
  147.            LPSTR lpszCmdLine,int nCmdShow)
  148. {
  149.   MSG              msg;
  150.     WNDCLASS         wndclass;
  151.     HWND             hwnd;
  152. #ifdef USES_BWCC
  153.     static HINSTANCE hBWCC;
  154. #endif
  155.  
  156.   SetInstance(hInstance);
  157.   if (!hPrevInstance){
  158.     wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  159.     wndclass.lpfnWndProc    = (WNDPROC)WndProc;
  160.     wndclass.cbClsExtra     = 0;
  161.     wndclass.cbWndExtra     = 0;
  162.     wndclass.hInstance      = hInstance;
  163.         wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
  164.     wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  165.     wndclass.hbrBackground  = COLOR_WINDOW + 1;
  166.     wndclass.lpszMenuName   = "AMENU";
  167.     wndclass.lpszClassName  = "flat";
  168.  
  169.     if (!RegisterClass(&wndclass))
  170.       return FALSE;
  171.     }
  172.  
  173. #ifdef USES_MEMCHECK
  174.     mc_startcheck(NULL);
  175. #endif
  176. #ifdef USES_BWCC
  177.     hBWCC = LoadLibrary("BWCC.DLL");
  178.     if ((UINT) hBWCC <= HINSTANCE_ERROR)
  179.         return FALSE;
  180. #endif 
  181.     hwnd = CreateWindow("flat", "Shareware Sales",
  182.                       WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  183.                       50, 50, 350, 220,
  184.                       NULL,
  185.                       NULL,
  186.                       hInstance,
  187.                                             NULL);
  188.     ShowWindow(hwnd, SW_SHOW);
  189.   UpdateWindow(hwnd);
  190.     while (GetMessage(&msg, NULL, 0, 0)){
  191.     TranslateMessage(&msg);
  192.     DispatchMessage(&msg);
  193.     }
  194. #ifdef USES_MEMCHECK
  195.     mc_endcheck();
  196. #endif
  197. #ifdef USES_BWCC
  198.     FreeLibrary(hBWCC);
  199. #endif
  200.   return msg.wParam;
  201. }  /* WinMain */
  202.  
  203. #pragma argsused
  204. TASKPROC _export WMWininichange (HWND hwnd,
  205.                                                                  UINT message,
  206.                                                                  WPARAM wParam,
  207.                                                                  LPARAM lParam)
  208. {
  209.     /* This is called each time the user changes the
  210.          WIN.INI file.  We are checking for a change
  211.          in the short date (mm/dd/yy) format */
  212.   SetDateFormat();
  213.     return 0;
  214. }  /* WMWininichange */
  215.  
  216. #pragma argsused
  217. TASKPROC _export WMCreate (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  218. {
  219.     SetDateFormat();
  220.     return 0;
  221. }
  222.  
  223. #pragma argsused
  224. TASKPROC _export WMCommand (HWND hwnd,
  225.                                                         UINT message,
  226.                                                         WPARAM wParam,
  227.                                                         LPARAM lParam)
  228. {
  229.     BOOL bDoit;
  230.  
  231.     switch(wParam) {
  232.         case IDM_ADD:
  233.             do{
  234.                 SetWork(DoNew);
  235.                 bDoit = ProcessSale(hwnd);
  236.                 if (bDoit)
  237.                     SaveNewSale();
  238.             }while(bDoit);
  239.             return 0;
  240.         case IDM_DELETE:
  241.             if (SetSearch(hwnd)){
  242.                 SetWork(DoDelete);
  243.                 if (!GetAllSearch())
  244.                     SetAllSearchs(hwnd);
  245.                 ShowSales(hwnd);
  246.             }
  247.             return 0;
  248.         case IDM_EDIT:
  249.             if (SetSearch(hwnd)){
  250.                 SetWork(DoEdit);
  251.                 if (!GetAllSearch())
  252.                     SetAllSearchs(hwnd);
  253.                 ShowSales(hwnd);
  254.             }
  255.             return 0;
  256.         case IDM_VIEW:
  257.             if (SetSearch(hwnd)){
  258.                 SetWork(DoView);
  259.                 if (!GetAllSearch())
  260.                     SetAllSearchs(hwnd);
  261.                 ShowSales(hwnd);
  262.       }
  263.             return 0;
  264.         case IDM_PRINT:
  265. #ifdef USES_BWCC
  266.             BWCCMessageBox(hwnd, "Not Implemented", "Flat", MB_OK|MB_ICONINFORMATION);
  267. #else
  268.             MessageBox(hwnd, "Not Implemented", "Flat", MB_OK|MB_ICONINFORMATION);
  269. #endif
  270.             return 0;
  271.         case IDM_CLOSE:
  272.             PostQuitMessage(0);
  273.             return 0;
  274.     }
  275.   return 0;
  276. }  /* WMCommand */
  277.  
  278.  
  279. #pragma argsused
  280. LONG CALLBACK _export WndProc(HWND hwnd,
  281.                                                             UINT message,
  282.                                                             WPARAM wParam,
  283.                                                             LPARAM lParam)
  284. {
  285.   int i = 0;     /* index used to reference the task list */
  286.  
  287.   while ((TaskList[i].msg != NULL) && (TaskList[i].msg != message))
  288.     i++;
  289.   return ((*TaskList[i].fnc)(hwnd, message, wParam, lParam));
  290. }
  291.